#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define Max(a,b) ((a)>(b)?(a):(b))
#define SIZE 10000
int maximumUniqueSubarray(int* nums, int numsSize) {
    int max=0,sum=0,left=0,right=0;
    int *flag=calloc( SIZE+1,sizeof(int) );
    for( ; right < numsSize; right++ ){
        flag[ nums[right] ]++;
        sum+=nums[right];
        while( flag[ nums[right] ] ==2 ){
            flag[ nums[left] ]--;
            sum-=nums[left++];
        }
        max=Max(max,sum);
    }
    return max;
}

int main(){
    //int n[]={4,2,4,5,6};
    int n[]={5,2,1,2,5,2,1,2,5};
    printf("%d\n",maximumUniqueSubarray(n,sizeof(n)/sizeof(int)));
    return 0;
}
